package com.lineage.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public final class ConfigAlt {
  private static final Log _log = LogFactory.getLog(ConfigAlt.class);
  
  public static short GLOBAL_CHAT_LEVEL;
  
  public static short WHISPER_CHAT_LEVEL;
  
  public static boolean WAR_DOLL;
  
  public static byte AUTO_LOOT;
  
  public static int LOOTING_RANGE;
  
  public static boolean ALT_NONPVP;
  
  public static boolean ALT_PUNISHMENT;
  
  public static boolean ALT_ATKMSG;
  
  public static boolean CLAN_ALLIANCE;
  
  public static int ALT_ITEM_DELETION_TIME;
  
  public static boolean ALT_WHO_COMMANDX;
  
  public static int ALT_WHO_TYPE;
  
  public static double ALT_WHO_COUNT;
  
  public static int ALT_WAR_TIME;
  
  public static int ALT_WAR_TIME_UNIT;
  
  public static int ALT_WAR_INTERVAL;
  
  public static int ALT_WAR_INTERVAL_UNIT;
  
  public static int ALT_RATE_OF_DUTY;
  
  public static boolean SPAWN_HOME_POINT;
  
  public static int SPAWN_HOME_POINT_RANGE;
  
  public static int SPAWN_HOME_POINT_COUNT;
  
  public static int SPAWN_HOME_POINT_DELAY;
  
  public static int ELEMENTAL_STONE_AMOUNT;
  
  public static int HOUSE_TAX_INTERVAL;
  
  public static int HOUSE_TAX_ADENA;
  
  public static int MAX_DOLL_COUNT;
  
  public static int MAX_NPC_ITEM;
  
  public static int MAX_PERSONAL_WAREHOUSE_ITEM;
  
  public static int MAX_CLAN_WAREHOUSE_ITEM;
  
  public static int DELETE_CHARACTER_AFTER_LV;
  
  public static boolean DELETE_CHARACTER_AFTER_7DAYS;
  
  public static int NPC_DELETION_TIME;
  
  public static int DEFAULT_CHARACTER_SLOT;
  
  public static int MEDICINE;
  
  public static int POWER;
  
  public static int POWERMEDICINE;
  
  public static int BaseResetPOWER;
  
  public static boolean DORP_ITEM;
  
  public static final int MAX_NPC = 35;
  
  public static int MAX_PARTY_SIZE;
  
  public static boolean METE_GIVE_POTION;
  
  public static List<Integer> DRAGON_KEY_MAP_LIST = new ArrayList<>();
  
  public static List<Integer> NO_AI_MAP_LIST = new ArrayList<>();
  
  public static boolean GM_OVERHEARD;
  
  public static boolean GM_OVERHEARD0;
  
  public static boolean GM_OVERHEARD4;
  
  public static boolean GM_OVERHEARD11;
  
  public static boolean GM_OVERHEARD13;
  
  public static boolean ALT_WARPUNISHMENT;
  
  public static int CHAR_BOOK_INIT_COUNT;
  
  public static int CHAR_BOOK_MAX_CHARGE;
  
  public static boolean QUIZ_SET_SWITCH;
  
  public static Calendar QUIZ_SET_RESET_TIME;
  
  public static int QUIZ_SET_TYPE;
  
  public static int QUIZ_SET_LEVEL;
  
  public static int[][] QUIZ_SET_LIST;
  
  public static String NO_CD;
  
  private static final String ALT_SETTINGS_FILE = "./config/altsettings.properties";
  
  public static void load() throws ConfigErrorException {
    Properties set = new Properties();
    try {
      InputStream is = new FileInputStream(new File("./config/altsettings.properties"));
      InputStreamReader isr = new InputStreamReader(is, "utf-8");
      set.load(isr);
      is.close();
      GM_OVERHEARD = Boolean.parseBoolean(set.getProperty("GM_OVERHEARD", "false"));
      GM_OVERHEARD0 = Boolean.parseBoolean(set.getProperty("GM_OVERHEARD0", "false"));
      GM_OVERHEARD4 = Boolean.parseBoolean(set.getProperty("GM_OVERHEARD4", "false"));
      GM_OVERHEARD11 = Boolean.parseBoolean(set.getProperty("GM_OVERHEARD11", "false"));
      GM_OVERHEARD13 = Boolean.parseBoolean(set.getProperty("GM_OVERHEARD13", "false"));
      GLOBAL_CHAT_LEVEL = Short.parseShort(set.getProperty("GlobalChatLevel", "30"));
      WHISPER_CHAT_LEVEL = Short.parseShort(set.getProperty("WhisperChatLevel", "5"));
      AUTO_LOOT = Byte.parseByte(set.getProperty("AutoLoot", "2"));
      LOOTING_RANGE = Integer.parseInt(set.getProperty("LootingRange", "3"));
      ALT_NONPVP = Boolean.parseBoolean(set.getProperty("NonPvP", "true"));
      ALT_PUNISHMENT = Boolean.parseBoolean(set.getProperty("Punishment", "true"));
      ALT_WARPUNISHMENT = Boolean.parseBoolean(set.getProperty("WarPunishment", "false"));
      CLAN_ALLIANCE = Boolean.parseBoolean(set.getProperty("ClanAlliance", "true"));
      ALT_ITEM_DELETION_TIME = Integer.parseInt(set.getProperty("ItemDeletionTime", "10"));
      if (ALT_ITEM_DELETION_TIME > 60)
        ALT_ITEM_DELETION_TIME = 60; 
      ALT_WHO_COMMANDX = Boolean.parseBoolean(set.getProperty("WhoCommandx", "false"));
      ALT_WHO_TYPE = Integer.parseInt(set.getProperty("Who_type", "0"));
      ALT_WHO_COUNT = Double.parseDouble(set.getProperty("WhoCommandcount", "1.0"));
      if (ALT_WHO_COUNT < 1.0D)
        ALT_WHO_COUNT = 1.0D; 
      String strWar = set.getProperty("WarTime", "2h");
      if (strWar.indexOf("d") >= 0) {
        ALT_WAR_TIME_UNIT = 5;
        strWar = strWar.replace("d", "");
      } else if (strWar.indexOf("h") >= 0) {
        ALT_WAR_TIME_UNIT = 11;
        strWar = strWar.replace("h", "");
      } else if (strWar.indexOf("m") >= 0) {
        ALT_WAR_TIME_UNIT = 12;
        strWar = strWar.replace("m", "");
      } 
      ALT_WAR_TIME = Integer.parseInt(strWar);
      strWar = set.getProperty("WarInterval", "4d");
      if (strWar.indexOf("d") >= 0) {
        ALT_WAR_INTERVAL_UNIT = 5;
        strWar = strWar.replace("d", "");
      } else if (strWar.indexOf("h") >= 0) {
        ALT_WAR_INTERVAL_UNIT = 11;
        strWar = strWar.replace("h", "");
      } else if (strWar.indexOf("m") >= 0) {
        ALT_WAR_INTERVAL_UNIT = 12;
        strWar = strWar.replace("m", "");
      } 
      ALT_WAR_INTERVAL = Integer.parseInt(strWar);
      SPAWN_HOME_POINT = Boolean.parseBoolean(set.getProperty("SpawnHomePoint", "true"));
      SPAWN_HOME_POINT_COUNT = Integer.parseInt(set.getProperty("SpawnHomePointCount", "2"));
      SPAWN_HOME_POINT_DELAY = Integer.parseInt(set.getProperty("SpawnHomePointDelay", "100"));
      SPAWN_HOME_POINT_RANGE = Integer.parseInt(set.getProperty("SpawnHomePointRange", "8"));
      ELEMENTAL_STONE_AMOUNT = Integer.parseInt(set.getProperty("ElementalStoneAmount", "300"));
      HOUSE_TAX_INTERVAL = Integer.parseInt(set.getProperty("HouseTaxInterval", "10"));
      HOUSE_TAX_ADENA = Integer.parseInt(set.getProperty("HouseTaxAdena", "2000"));
      MAX_DOLL_COUNT = Integer.parseInt(set.getProperty("MaxDollCount", "1"));
      MAX_NPC_ITEM = Integer.parseInt(set.getProperty("MaxNpcItem", "8"));
      MAX_PERSONAL_WAREHOUSE_ITEM = Integer.parseInt(set.getProperty("MaxPersonalWarehouseItem", "100"));
      MAX_CLAN_WAREHOUSE_ITEM = Integer.parseInt(set.getProperty("MaxClanWarehouseItem", "200"));
      DELETE_CHARACTER_AFTER_LV = Integer.parseInt(set.getProperty("DeleteCharacterAfterLV", "60"));
      DELETE_CHARACTER_AFTER_7DAYS = Boolean.parseBoolean(set.getProperty("DeleteCharacterAfter7Days", "True"));
      NPC_DELETION_TIME = Integer.parseInt(set.getProperty("NpcDeletionTime", "10"));
      DEFAULT_CHARACTER_SLOT = Integer.parseInt(set.getProperty("DefaultCharacterSlot", "4"));
      MEDICINE = Integer.parseInt(set.getProperty("Medicine", "20"));
      POWER = Integer.parseInt(set.getProperty("Power", "35"));
      POWERMEDICINE = Integer.parseInt(set.getProperty("MedicinePower", "45"));
      BaseResetPOWER = Integer.parseInt(set.getProperty("BaseResetPOWER", "37"));
      DORP_ITEM = Boolean.parseBoolean(set.getProperty("dorpitem", "true"));
      METE_GIVE_POTION = Boolean.parseBoolean(set.getProperty("MeteGivePotion", "false"));
      CHAR_BOOK_INIT_COUNT = Integer.parseInt(set.getProperty("CharBookInitCount", "60"));
      CHAR_BOOK_MAX_CHARGE = Integer.parseInt(set.getProperty("CharBookMaxCharge", "4"));
      NO_CD = set.getProperty("NO_CD", "null");
      WAR_DOLL = Boolean.parseBoolean(set.getProperty("war_doll", "true"));
      QUIZ_SET_SWITCH = Boolean.parseBoolean(set.getProperty("QuizSetSwitch", "false"));
      String tmp10 = set.getProperty("QuizSetResetTime", "");
      if (!tmp10.equalsIgnoreCase("null")) {
        String[] temp = tmp10.split(":");
        if (temp.length == 3) {
          Calendar cal = Calendar.getInstance();
          cal.set(11, Integer.parseInt(temp[0]));
          cal.set(12, Integer.parseInt(temp[1]));
          cal.set(13, Integer.parseInt(temp[2]));
          QUIZ_SET_RESET_TIME = cal;
        } else {
          _log.info("[每日一题系统] 重置时间有误, 请重新设置!");
        } 
      } 
      QUIZ_SET_TYPE = Integer.parseInt(set.getProperty("QuizSetType", "1"));
      QUIZ_SET_LEVEL = Integer.parseInt(set.getProperty("QuizSetLevel", "0"));
      String tmp11 = set.getProperty("QuizSetList", "");
      if (!tmp11.equalsIgnoreCase("null")) {
        String[] temp2 = tmp11.split(",");
        int size = temp2.length;
        QUIZ_SET_LIST = new int[size][2];
        int i = 0;
        while (i < size) {
          String[] temp3 = temp2[i].split(":");
          QUIZ_SET_LIST[i][0] = Integer.valueOf(temp3[0]).intValue();
          QUIZ_SET_LIST[i][1] = Integer.valueOf(temp3[1]).intValue();
          i++;
        } 
      } 
      if (set.getProperty("DragonKeyMapList") != null) {
        String[] split;
        int length = (split = set.getProperty("DragonKeyMapList").split(",")).length;
        int j = 0;
        while (j < length) {
          String str = split[j];
          DRAGON_KEY_MAP_LIST.add(Integer.valueOf(Integer.parseInt(str)));
          j++;
        } 
      } 
    } catch (Exception e) {
      throw new ConfigErrorException("设置档案遗失: ./config/altsettings.properties");
    } finally {
      set.clear();
    } 
  }
}
